package com.thrd.taiexhibition.fragement;

import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.thrd.basicframework.bean.BaseFragment;
import com.thrd.basicframework.ui.defaultview.LoadingState;
import com.thrd.taiexhibition.R;
import com.thrd.taiexhibition.adapter.ResearchAdapter;
import com.thrd.taiexhibition.bean.BeanResearch;
import com.thrd.taiexhibition.presener.ResearchPresener;
import com.thrd.taiexhibition.view.ResearchView;

import java.util.List;

/**
 * @author: ${唐杰}
 * @date: 2021/3/30
 * 有聊调研
 */
public class ResearchFragment extends BaseFragment implements ResearchView {

    private ResearchAdapter mResearchAdapter;
    private RecyclerView mRecyclerView;
    private ResearchPresener mResearchPresener;

    @Override
    protected int setLayoutResourceID() {
        return R.layout.fragment_research;
    }

    @Override
    protected void setUpView(View mContentView) {
        mRecyclerView = mContentView.findViewById(R.id.rv_recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getMContext()));

    }

    @Override
    protected void setUpData() {
        mResearchPresener = new ResearchPresener(this);

        mResearchAdapter = new ResearchAdapter(getMContext(),null);
        mRecyclerView.setAdapter(mResearchAdapter);
    }

    @Override
    public void onFragmentFirstVisible() {
        super.onFragmentFirstVisible();
        mResearchPresener.getResearchData();
    }

    @Override
    public void onError(String error, int type) {
        getContentView().setState(LoadingState.STATE_ERROR);
    }

    @Override
    public void onSuccess(List<BeanResearch> map) {
        mResearchAdapter.refresh(map);
        getContentView().setState(LoadingState.STATE_SUCCESS);
    }
}
